#pragma once
#include "shm.h"
#include <iostream>
#include <cstring>
#include <string>
#include <map>

#define SRC_NUMS 6

using namespace std;

struct monitor_content
{
	char _ip[16];  
	int _port;
	time_t _start_time;

	unsigned long _all_request_nums;
	unsigned long _valid_request_nums;

	unsigned long _all_response_nums;
	unsigned long _valid_response_nums;
	
	unsigned long _delay_over_600ms_nums;
	unsigned long _delay_over_800ms_nums;
	unsigned long _delay_over_1s_nums;
	unsigned long _delay_over_2s_nums;

	time_t _last_response_time;
	long long _last_handle_time;//use long long because dce/timewarp.h: timee::operator - 
	
	long long _all_delay;
	long long _max_delay;
	
	int _wait_request_nums;
};

class monitor_writer : public write_shm
{
	monitor_content *_content;

//	pthread_mutex_t _mutex; 
public:
	monitor_writer(){_content = NULL;}
	~monitor_writer(){
//		pthread_mutex_unlock(&_mutex);
		release();
	}
	
	int init_monitor(int ser = 1,int size = 4096);
	
	int write_ip(char *ip);
	int write_port(int port);
	
	int write_start_time(time_t tv);
	
	int add_all_request_nums();
	int add_valid_request_nums();
	
	int add_all_response_nums();//need lock
	int add_valid_response_nums();//need lock
	
	int write_last_response_time(time_t tv);//need lock?
	int write_last_handle_time(long long time);//need lock?
	
	int add_all_delay(long long time);//need lock
	int write_max_delay(long long time);//lock

	int write_wait_request_nums(int nums);

};



